package com.nsgf.library.ui.page;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.state.State;
import com.nsgf.library.BR;
import com.nsgf.library.R;
import com.nsgf.library.databinding.ActivityNsgfMainBinding;
import com.nsgf.library.databinding.ActivityNsgfMaintenanceBinding;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.ui.adapter.XFragmentAdapter;
import com.nsgf.library.ui.page.fragment.MaintenanceFragment;
import com.nsgf.library.ui.page.fragment.MessageFragment;
import com.nsgf.library.ui.page.manager.WorkCreateActivity;
import com.nsgf.library.utils.PublicMethodUtils;
import com.nsgf.library.widget.prckerview.OptionsPickerView;

import java.util.ArrayList;
import java.util.List;

/**
 * 维修养护
 */

public class MaintenanceActivity extends BaseActivity {


    private List<Fragment> fragmentList = new ArrayList<>();

    private String[] mPageTitleList;
    private AccountRequester mAccountRequester;

    private MaintenanceStates mStates;

    private ActivityNsgfMaintenanceBinding mBinding;

    @Override
    protected void initViewModel() {
        mStates = new MaintenanceStates();
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.activity_nsgf_maintenance, BR.vm, mStates)
                .addBindingParam(BR.click, new ClickProxy());
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mBinding = (ActivityNsgfMaintenanceBinding) getBinding();
        mStates.titleBar.set("维修养护");
        fragmentList.add(MaintenanceFragment.newInstance(0));
        fragmentList.add(MaintenanceFragment.newInstance(1));
        mPageTitleList = new String[]{"维修项目", "养护项目"};
        XFragmentAdapter adapter = new XFragmentAdapter(this, getSupportFragmentManager(), fragmentList, mPageTitleList);
        mBinding.viewPager.setAdapter(adapter);

        PublicMethodUtils.initMagicIndicator(mBinding.magicIndicator, mBinding.viewPager, mPageTitleList, this);

    }


    public static class MaintenanceStates extends StateHolder {

        public final State<String> screenType = new State<>("");
        public final State<String> time = new State<>("");
    }

    private int timeIndex = 0;

    public class ClickProxy {

        public void screenTime() {

            final ArrayList<String> list = new ArrayList<>();
            list.add("全部");
            list.add("2025");
            list.add("2024");
            list.add("2023");
            list.add("2022");
            list.add("2021");
            list.add("2020");
            list.add("2019");
            list.add("2018");
            list.add("2017");
            list.add("2016");
            list.add("2015");
            list.add("2014");
            list.add("2013");
            list.add("2012");
            list.add("2011");
            list.add("2010");
            OptionsPickerView<String> mOptionsPickerView = new OptionsPickerView.Builder(MaintenanceActivity.this, new OptionsPickerView.OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    if (options1 == 0)
                        mStates.time.set("");
                    else
                        mStates.time.set(list.get(options1));
                    for (Fragment fragment : fragmentList) {
                        ((MaintenanceFragment) fragment).getDatas(mStates.time.get());
                    }
                    timeIndex = options1;
                }
            }).build();
            mOptionsPickerView.setPicker(list);
            mOptionsPickerView.setSelectOptions(timeIndex);
            mOptionsPickerView.show();
        }
    }


}
